package com.banciyuan.bcywebview.biz.main.newdiscover.index.discoverholder;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.biz.groupdetail.NewTeamDetailActivity;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import de.greenrobot.daoexample.model.Timeline;

/**
 * Created by squall on 2017/3/22.
 */

public class GroupDiscoverHolder extends BaseDiscoverHolder {

    private TextView tvGroupTeamTitle;
    private TextView tvGroupTeamDesc;
    private TextView tvGroupTeamJoin;
    private View viewBody;
    private ImageView ivGroupCover;

    public GroupDiscoverHolder(View itemView) {
        super(itemView);
        tvGroupTeamTitle = (TextView) itemView.findViewById(R.id.group_team_title);
        tvGroupTeamDesc = (TextView) itemView.findViewById(R.id.group_team_desc);
        tvGroupTeamJoin = (TextView) itemView.findViewById(R.id.group_team_join_num);
        viewBody = itemView.findViewById(R.id.group_view_container);
        ivGroupCover = (ImageView) itemView.findViewById(R.id.group_team_cover);
    }

    @Override
    public void renderData(final Timeline mItem, final Context mContext) {
        super.renderData(mItem, mContext);
        if (!TextUtils.isEmpty(mItem.getGroupTitle())) {
            tvGroupTeamTitle.setText(Html.fromHtml(mItem.getGroupTitle()));
        }
        if ("0".equals(mItem.getPost_num())) {
            tvGroupTeamJoin.setText(mContext.getString(R.string.post_message));
        } else {
            tvGroupTeamJoin.setText(String.format(mContext.getString(R.string.join_talk_card), mItem.getPost_num()));
        }
        if (TextUtils.isEmpty(mItem.getContentAddress())) {
            ivGroupCover.setVisibility(View.GONE);
        } else {
            ivGroupCover.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(mItem.getContentAddress(), ivGroupCover, ImageOptions.options);
        }
        if (TextUtils.isEmpty(mItem.getIntro())) {
            tvGroupTeamDesc.setVisibility(View.GONE);
        } else {
            tvGroupTeamDesc.setVisibility(View.VISIBLE);
            tvGroupTeamDesc.setText(Html.fromHtml(mItem.getIntro()));
        }

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gotoUtil.gotoAct(mContext, NewTeamDetailActivity.class, mItem.getGid(), mItem.getGname());
            }
        });
    }
}
